package com.buobao.screenlogcat

import android.util.Log
import androidx.lifecycle.MutableLiveData
import java.lang.Exception

private val running = arrayOf("logcat", "-s", "adb logcat *: W")

val logObserver = MutableLiveData("")

fun processingLog() {
    val exec = Runtime.getRuntime().exec(running)
    val inputStream = exec.inputStream
    Thread {
        try {
            var len: Int
            val buffer = ByteArray(1024)
            while (true) {

                len = inputStream.read(buffer)
                Log.i("print","$len")
                if (len > 0) {
                    logObserver.postValue(logObserver.value + String(buffer))
                }
            }

        } catch (e: Exception) {
            e.printStackTrace()
        }
    }.start()
}